<?

function greetings_audio( $fid) {
	global $user;
	if ( $fid != 'comfort_default' || $fid != 'comfort_curr') {
		ippbx_set_db();
		$path = db_result(db_query('SELECT Path FROM GreetingFiles WHERE ID=%d', $fid));
		ippbx_unset_db();
	} else {
		if ($fid == 'comfort_default') {
			$path = variable_get('comfort_default','sites/default/files/audio.mp3');
		} else {
			ippbx_set_db();
			$path = db_result(db_query('SELECT Music FROM UserProfile WHERE ID_User=%d', $user->uid));
			ippbx_unset_db();
		}
	}
	
	$file_size = filesize($path);
	$file_data = file_get_contents($path);

	drupal_set_header('Content-Type: audio/mpeg');
	print "Content-Length: $file_size\n";
	print "Accept-Ranges: bytes\n\n";
	print "Connection: close\n\n";
	print $file_data;
	exit();
}

?>